//
// Created by jmdvirus on 2020/3/27 下午4:57.
// Copyright (c) 2020 benewtech All rights reserved.
//
//     ******          *             *--*
//       ||            *             |
//       ||  *--*--*---*  * *-********--*
//   *  //   *  *  *   *\ / ||  |  |    |
//    **    *  *  *---* *  *   *--* *--*
//

#include "CMMediaOperationBase.h"
#include "cm_logprint.h"

#include <iostream>

CMMediaOperationBase::CMMediaOperationBase()
{
    m_height = 0;
    m_width = 0;
    m_buf = NULL;
    m_bufSize = 0;
}

CMMediaOperationBase::~CMMediaOperationBase()
{
    if (m_buf)
    {
        free(m_buf);
    }
    m_buf = NULL;
}

void CMMediaOperationBase::setParam(int width, int height)
{
    m_width = width;
    m_height = height;
    size_t len = m_width * m_height * 3 / 2;
    if (!m_buf || len > m_bufSize)
    {
        unsigned char *tmp = (unsigned char *)realloc(m_buf, len * sizeof(unsigned char));
        if (!tmp)
        {
            cmerror("malloc fail, must check it size = [%lu]\n", len);
        }
        else
        {
            m_buf = tmp;
            m_bufSize = len;
        }
    }
}
